<template>
  <view class="form-container">
    <uni-forms ref="form" :modelValue="formState" :rules="rules" labelPosition="top">
      <view class="background-white bor-top">
        <uni-forms-item name="fileContent" label="今日学习文件精神内容：" :label-width="200" required>
          <textarea v-model="formState.fileContent" class="text-area" placeholder="请输入" maxlength="1000" />
        </uni-forms-item>
      </view>
      <view class="hidden-title">奖惩情况：</view>
      <cu-cell-group>
        <uni-forms-item name="award">
          <cu-cell title="奖励(条)" required>
            <input
              type="number"
              v-model="formState.award"
              placeholder="请输入"
              class="input"
              placeholder-class="form-placeholder__style"
              maxlength="6"
            />
          </cu-cell>
        </uni-forms-item>

        <uni-forms-item name="punishment">
          <cu-cell title="惩罚(条)" required>
            <input
              type="number"
              v-model="formState.punishment"
              placeholder="请输入"
              class="input"
              placeholder-class="form-placeholder__style"
              maxlength="6"
            />
          </cu-cell>
        </uni-forms-item>

        <uni-forms-item name="notice">
          <cu-cell title="通报(条)" required>
            <input
              type="number"
              v-model="formState.notice"
              placeholder="请输入"
              class="input"
              placeholder-class="form-placeholder__style"
              maxlength="6"
            />
          </cu-cell>
        </uni-forms-item>
      </cu-cell-group>

      <view class="background-white bor-top">
        <uni-forms-item name="handleContent" label="工作要求：" :label-width="100" required>
          <textarea v-model="formState.handleContent" class="text-area" placeholder="请输入" maxlength="1000" />
        </uni-forms-item>
      </view>

      <view class="background-white bor-top bottom">
        <uni-forms-item name="files" label="图片（最多三张）：" labelWidth="150">
          <image-upload state="edit" :imageUrl="formState.files" @change="imageOnChange"> </image-upload>
        </uni-forms-item>
      </view>
    </uni-forms>
    <view class="submit" @click="handleSubmit">汇报</view>
  </view>
</template>

<script>
import CuUserSelector from '@/components/CuUserSelector/index.vue'
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
import CuCellBackNodesSelect from '@/components/CuCellBackNodesSelect/index.vue'
import ImageUpload from '@/components/image-upload/index.vue'
import CuCell from '@/components/cu-cell/cu-cell.vue'
import { zhHandle } from '@/api/duty-basic/duty-meeting'

export default {
  name: '',
  data() {
    return {
      meetingId: '',
      procTaskId: '',
      formState: {
        handleContent: '', // 工作内容
        files: '',
        award: 0,
        punishment: 0,
        notice: 0,
        fileContent: ''
      },
      rules: {
        fileContent: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        },
        handleContent: {
          rules: [
            {
              required: true,
              errorMessage: '工作内容不能为空'
            }
          ]
        },
        award: {
          rules: [
            {
              required: true,
              errorMessage: '奖励不能为空'
            }
          ]
        },
        punishment: {
          rules: [
            {
              required: true,
              errorMessage: '惩罚不能为空'
            }
          ]
        },
        notice: {
          rules: [
            {
              required: true,
              errorMessage: '通报不能为空'
            }
          ]
        }
      }
    }
  },
  components: { CuUserSelector, CuCellGroup, CuCellBackNodesSelect, ImageUpload, CuCell },
  methods: {
    imageOnChange(urlList) {
      this.formState.files = urlList.join(',')
    },
    async handleSubmit() {
      await this.$refs.form.validate()
      uni.showModal({
        content: '提交后，填写的内容将不可以修改，请确定填写无误后再提交',
        confirmText: '确定',
        success: async (res) => {
          if (res.confirm) {
            await zhHandle({ ...this.formState, meetingId: this.meetingId, procTaskId: this.procTaskId })
            uni.showToast({
              title: '提交成功！',
              icon: 'success',
              duration: 2000,
              success() {
                uni.navigateBack()
              }
            })
          }
        }
      })
    }
  },
  onReady() {
    // 需要在onReady中设置规则
    this.$refs.form.setRules(this.rules)
  },
  onLoad({ id, procTaskId }) {
    this.procTaskId = procTaskId
    this.meetingId = id
  }
}
</script>

<style lang="scss" scoped>
.text-area {
  height: 300rpx;
}

.submit {
  width: 600rpx;
  height: 88rpx;
  background: #454a5e;
  border-radius: 50rpx 50rpx 50rpx 50rpx;
  opacity: 1;
  text-align: center;
  line-height: 88rpx;
  font-size: 36rpx;
  font-weight: 400;
  color: #ffffff;
  margin: 0 auto;
  margin-top: 70rpx;
  margin-bottom: 70rpx;
}

.form-item-label-position-left {
  flex-direction: row !important;
  background: #fff;
  padding: 0 30rpx;
  padding-right: 20rpx;
  position: relative;
  box-sizing: border-box;
  min-height: 100rpx;
  align-items: center;
  margin-bottom: 0;

  & ::v-deep .uni-forms-item__label {
    height: auto;
    padding-bottom: 0rpx !important;
  }

  & ::v-deep .uni-data-checklist,
  & ::v-deep .uni-forms-item__content {
    position: initial;
  }

  & ::v-deep .uni-forms-item__error {
    left: 30rpx;
    top: 62%;
  }
}

.form-item-label-position-left::before {
  content: '';
  height: 1rpx;
  width: calc(100% - 30rpx);
  bottom: 0;
  left: 30rpx;
  position: absolute;
  background: #d5d7e3;
}

.checkbox {
  padding-left: 30rpx;
}
</style>
